
package com.azxc.rapid.plus.system.service.impl;

import com.azxc.rapid.core.mp.base.BaseServiceImpl;
import com.azxc.rapid.core.tool.utils.Func;
import com.azxc.rapid.plus.system.dto.RoleConfigManagerDTO;
import com.azxc.rapid.plus.system.entity.RoleConfigManager;
import com.azxc.rapid.plus.system.vo.RoleConfigManagerVO;
import com.azxc.rapid.plus.system.mapper.RoleConfigManagerMapper;
import com.azxc.rapid.plus.system.service.IRoleConfigManagerService;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.checkerframework.checker.units.qual.A;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.metadata.IPage;

import java.util.ArrayList;
import java.util.List;

/**
 * 角色管理 服务实现类
 * @since 2023-07-06
 */
@Service
public class RoleConfigManagerServiceImpl extends BaseServiceImpl<RoleConfigManagerMapper, RoleConfigManager> implements IRoleConfigManagerService {

	@Override
	public IPage<RoleConfigManagerVO> selectRoleConfigManagerPage(IPage<RoleConfigManagerVO> page, RoleConfigManagerVO roleConfigManager) {
		return page.setRecords(baseMapper.selectRoleConfigManagerPage(page, roleConfigManager));
	}

    @Override
    public Boolean saveRoleRel(RoleConfigManagerDTO roleConfigManager) {
		this.remove(Wrappers.<RoleConfigManager>lambdaQuery().eq(RoleConfigManager::getMasterRoleId,roleConfigManager.getMasterRoleId()));
		List<Long> slaveRoleIds = roleConfigManager.getSlaveRoleIds();
		List<RoleConfigManager> list = new ArrayList<>();
		for (Long slaveRoleId:slaveRoleIds){
			RoleConfigManager roleConfig = new RoleConfigManager();
			roleConfig.setMasterRoleId(roleConfigManager.getMasterRoleId());
			roleConfig.setSlaveRoleId(slaveRoleId);
			list.add(roleConfig);
		}
		Boolean rs = true;
		if(list.size()>0){
			rs = this.saveBatch(list);
		}
		return rs;
    }

	@Override
	public List<RoleConfigManagerVO> getRoleListByMasterRoleId(String roleIds) {
		return this.baseMapper.getRoleListByMasterRoleId(Func.toLongList(roleIds));
	}

}
